<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="registrationForm" enctype="multipart/form-data">
                <br/>
                <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 
                <fieldset>
                    <br/>
                    <div style="float: left;width: 100%">
                        <h3 class="title" style="float: left">Averbação de mudança de nome</h3>
                    </div>

                    <ui:include src="averbacaocabecalho.xhtml"/>  
                    <ui:include src="averbacaorodape.xhtml"/>  

                    <p:panel id="panel" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">

                        <p:dataTable id="tableProprietario" var="item" value="#{managerAverbacao.imovel.proprietarios}" 
                                     styleClass="grid_24" emptyMessage="Nenhum registro">  
                            <f:facet name="header">
                                Nome do Proprietário ou Detentor
                            </f:facet>

                            <p:column headerText="Ação" style="text-align: center">
                                <p:commandButton  styleClass="optionButton" alt="Mudar Nome"
                                                  process="@this" icon="ui-icon-pencil"
                                                  actionListener="#{managerAverbacao.mudarProprietario(item)}"
                                                  update=":registrationForm:dlgNewName"
                                                  oncomplete="dlgNewName.show()" />
                            </p:column>

                            <p:column headerText="Nome">  
                                #{item.tipoDocumento ne null ? 
                                  (item.tipoDocumento eq 'CPF' ? item.nome : item.nomeFantasia) : 
                                  (item.nome ne null and item.nome ne '' ? item.nome : item.nomeFantasia)}
                            </p:column>

                            <p:column headerText="Documento" >  
                                #{item.formatedDocument()}
                            </p:column> 

                        </p:dataTable>   
                    </p:panel>

                        </fieldset>
                        <div class="buttonAction">
                            <p:commandButton actionListener="#{managerAverbacao.redirectAverbacao()}" update="@form" process="@this" value="Cancelar"  icon="ui-icon-trash" />
                        </div >

                <p:dialog header="Mudança de nome" id="dlgNewName" widgetVar="dlgNewName" width="325" modal="true">
                    <p:outputLabel value="Novo nome" styleClass="grid_24"  />
                    <p:inputText value="#{managerAverbacao.novoNome}" styleClass="grid_24" />
                    <div class="buttonAction grid_24" >
                        <p:commandButton value="Salvar" icon="ui-icon-disk"
                                         id="saveButton"
                                         actionListener="#{managerAverbacao.salvarAverbacaoMudancaNome()}"
                                         styleClass="ui-priority-primary"   />
                        <p:button href="#" onclick="dlgNewName.hide()" value="Cancelar"  icon="ui-icon-trash" />
                    </div >

                </p:dialog>
                <br/>
                <ui:include src="averbacao_dialog.xhtml"/>  

            </h:form>
        </ui:define>
    </ui:composition>

</html>
